package com.zeldu.question.controller;


import com.zeldu.common.model.response.CommonCode;
import com.zeldu.common.model.response.QueryResponseResult;
import com.zeldu.common.model.response.QueryResult;
import com.zeldu.common.model.response.ResponseResult;
import com.zeldu.question.pojo.questionLibrary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("library")
public class libraryController {
    @Autowired(required = false)
    private com.zeldu.question.service.libraryService libraryService;

    @RequestMapping("/once")
    @ResponseBody
    public ResponseResult once(@RequestBody questionLibrary questionLibrary){
        int t = libraryService.response(questionLibrary);
        if(t == 1){
            return new ResponseResult(CommonCode.SUCCESS);
        }
        else return new ResponseResult(CommonCode.FAIL);
    }

    @RequestMapping("/get")
    @ResponseBody
    public ResponseResult get(@RequestBody questionLibrary questionLibrary){
        QueryResult<questionLibrary> queryResult=new QueryResult<>();
        List<questionLibrary> libraries = libraryService.getQues(questionLibrary.getSubject());
        queryResult.setList(libraries);
        queryResult.setTotal(libraries.size());
        return new QueryResponseResult<>(CommonCode.SUCCESS,queryResult);
    }
}
